package com.cat.greedyAlgorithm;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/largest-element-in-an-array-after-merge-operations/
 * @create 2025/8/25 10:26
 * @since JDK17
 */

public class Solution31 {
    public long maxArrayValue(int[] nums) {
        int n = nums.length;
        long ans = 0;
        for (int i = n - 1; i > 0; i--) {
            ans = Math.max(ans, nums[i]);
            if (ans > nums[i - 1]) {
                ans += nums[i - 1];
            }
        }

        return ans;
    }
}
